package com.ruoyi.plugs.knife4j.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.ruoyi.common.config.RuoYiConfig;
import org.springframework.core.annotation.Order;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@Order(100)
@EnableKnife4j
@EnableSwagger2
public class Knife4jConfiguration {
    /** 是否开启Knife4j */
    @Value("${knife4j.enable:false}")
    private boolean enable;

    @Bean(value = "defaultApi2")
    public Docket defaultApi2() {
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                // 是否启用Swagger
                .enable(enable)
                .apiInfo(new ApiInfoBuilder()
                        .title("my knife4j api")
                        .description("my restful api")
                        .termsOfServiceUrl("www.baidu.com")
                        .contact(new Contact(RuoYiConfig.getName(), "www.baidu.com", "dxl0321@qq.com"))
                        .version("1.0")
                        .build())
                .groupName("group 1.0.0")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.ruoyi"))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }
}
